package com.mall.b2c.bean;

import org.apache.commons.httpclient.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import com.mall.b2c.domain.member.CommentDomain;
import com.mall.b2c.domain.order.OrderItemDomain;

public class CommentBean {
	private Long id;
	private String userName;
	private String content;
	private Integer score;
	private String ip;
	private String commentDate;
	private Boolean isDeleted;
	private String deletePerson;

	private String productCode; //商品编号
	private String productName; //商品名称
	private String spec;        //商品规格
	private String buyDate;     //购买日期

	public CommentBean(CommentDomain comment) {
		BeanUtils.copyProperties(comment, this, new String[]{"commentDate"});
		if(comment.getAnonymous() == null || comment.getAnonymous().equals(Boolean.TRUE)) {
			if(StringUtils.isNotBlank(this.userName)) {
				this.userName = this.userName.charAt(0) + "***" + this.userName.charAt(this.userName.length() - 1);
			}
		}
		setCommentDate(DateUtil.formatDate(comment.getCommentDate(), "yyyy-MM-dd HH:mm:ss"));
		OrderItemDomain item = comment.getOrderItem();
		if(item != null){
			setProductCode(item.getProductCode());
			setProductName(item.getProductName());
			setSpec(item.getSpecification());
			setBuyDate(DateUtil.formatDate(item.getOrder().getCreateDate(), "yyyy-MM-dd HH:mm:ss"));
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}


	public String getUserName() {
		return userName;
	}


	public void setUserName(String userName) {
		this.userName = userName;
	}


	public String getContent() {
		return content;
	}


	public void setContent(String content) {
		this.content = content;
	}

	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	public String getIp() {
		return ip;
	}


	public void setIp(String ip) {
		this.ip = ip;
	}


	public String getCommentDate() {
		return commentDate;
	}


	public void setCommentDate(String commentDate) {
		this.commentDate = commentDate;
	}


	public Boolean getIsDeleted() {
		return isDeleted;
	}


	public void setIsDeleted(Boolean isDeleted) {
		this.isDeleted = isDeleted;
	}


	public String getDeletePerson() {
		return deletePerson;
	}


	public void setDeletePerson(String deletePerson) {
		this.deletePerson = deletePerson;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getSpec() {
		return spec;
	}

	public void setSpec(String spec) {
		this.spec = spec;
	}

	public String getBuyDate() {
		return buyDate;
	}

	public void setBuyDate(String buyDate) {
		this.buyDate = buyDate;
	}
}
